package com.oj.friend.controller.user;

import com.oj.common.core.constants.HttpConstants;
import com.oj.common.core.constants.JwtConstants;
import com.oj.common.core.controller.BaseController;
import com.oj.common.core.domain.R;
import com.oj.common.core.domain.TableDataInfo;
import com.oj.friend.domain.exam.dto.ExamDTO;
import com.oj.friend.domain.exam.dto.ExamQueryDTO;
import com.oj.friend.service.impl.UserExamServiceImpl;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

/**
 * @Description
 * @Author bin
 * @Date 2025/6/4
 */
@RestController
@RequestMapping("/user/exam")
public class UserExamController extends BaseController {

    @Resource
    private UserExamServiceImpl userExamService;

    @PostMapping("/enter")
    @Operation(summary = "报名竞赛接口", description = "建立user和exam的关系 报名竞赛")
    public R<Void> enter(@RequestHeader(HttpConstants.AUTHENTICATION) String token, @RequestBody ExamDTO examDTO) {
        return toR(userExamService.enter(token, examDTO.getExamId()));
    }


    @GetMapping("/list")
    @Operation(summary = "我的竞赛列表", description = "直接显示当前用户历史报名过的竞赛")
    @ApiResponse(responseCode = "1000", description = "操作成功")
    @ApiResponse(responseCode = "2000", description = "服务器繁忙,请稍后重试")
    public TableDataInfo list(ExamQueryDTO examQueryDTO) {
        return userExamService.list(examQueryDTO);
    }

}
